package com.ihd.ihardware.view.lock.viewmodel;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.support.annotation.NonNull;

import com.ihd.ihardware.view.lock.model.LockRepository;

public class LockBindViewModel extends AndroidViewModel {

    private LockRepository mLockRepository;

    public LockBindViewModel(@NonNull Application application) {
        super(application);
    }

    public void bind(String originalData) {
        if (mLockRepository == null)
            mLockRepository = new LockRepository();
        mLockRepository.bind(originalData);
    }

    public void unbind(String id) {
        if (mLockRepository == null)
            mLockRepository = new LockRepository();
        mLockRepository.unbind(id);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        if (null != mLockRepository) {
            mLockRepository.onDestroy();
            mLockRepository = null;
        }
    }
}
